<template>
    <fy-card style="text-align: center">
        <template #body>
            <img class="avatar" :src="user.avatar" @click="avatarClick"/>
            <div class="username">{{user.nickname}}</div>
            <div class="slogan">{{user.slogan}}</div>
            <div class="statics-wrapper">
                    <div class="statics-item" v-for="(item, index) in statics" :key="index" @click="clickItem(item, index)">
                        <span class="statics-item-title">{{item.title}}</span><br/><span class="statics-item-num">{{item.num}}</span>
                    </div>
            </div>
        </template>
    </fy-card>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { useUserStore} from '@/stores/user.js'

import FyCard from "@/components/base/FyCard.vue";

defineProps({
    statics: {
        type: Object,
        require: true
    }
})

const userStore = useUserStore();
let user = ref({});

const statics = ref([
    {"title": "文章", "num": 23},
    {"title": "标签", "num": 7},
    {"title": "分类", "num": 3}
])

const router = useRouter();

const avatarClick = () => {
    router.push({name: 'about'})
}

const clickItem = (item, index) => {
    console.log(item, index);
    if (index === 0) {
        router.push({name: 'archieves'})
    } else if (index === 1) {
        router.push({name: 'tags'})
    } else if (index === 2) {
        router.push({name: 'categories'})
    }
}

onMounted(() => {
    userStore.getUserInfo("123456").then((result) => {
    console.log("用户信息：", result);
    user.value = result;
  })  
})

</script>

<style lang="scss" scoped>

.avatar {
    cursor: pointer;
    width: 100px; 
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto;
    display: block;
    transition: transform 0.3s ease;
    &:hover {
        transform: scale(1.1);
    }
}

.username {
    font-size: 20px;
    font-weight: 600;
    margin-top: 15px;
}

.slogan {
    font-size: 14px;
    line-height: 18px;
    margin-top: 5px;
    padding: 0 12px;
}

.statics-wrapper {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    padding: 0 30px;
    margin-top: 30px;
    // background-color: blueviolet;
}

.statics-item {
    // background-color: plum;
    text-align: center;
    cursor: pointer;
    &:hover {
        color: var(--primary-color);
    }
}

.statics-item-title {
    font-size: 16px;
}

.statics-item-num {
    font-size: 15px;
}

</style>